package com.gin.kotlin.no_gay_alliance.adapter.follow

import android.content.Context
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions
import com.gin.kotlin.no_gay_alliance.R
import com.gin.kotlin.no_gay_alliance.activity.UserCenterActivity
import com.gin.kotlin.no_gay_alliance.base.AbstractBindingRecyclerViewAdapter
import com.gin.kotlin.no_gay_alliance.base.GlideModule.Companion.CROSS_FADE
import com.gin.kotlin.no_gay_alliance.base.MyHandler
import com.gin.kotlin.no_gay_alliance.base.TextViewTarget
import com.gin.kotlin.no_gay_alliance.databinding.ItemFollowedUserBinding
import com.gin.nga.enums.status.AccountStatus
import com.gin.nga.response.user.FollowedUser

class FollowedUserAdapter(context: Context, handler: MyHandler) : AbstractBindingRecyclerViewAdapter<ItemFollowedUserBinding, FollowedUser>(context, handler) {
    override fun onBindViewHolder(holder: ViewHolder<ItemFollowedUserBinding>, position: Int, b: ItemFollowedUserBinding, dataModel: FollowedUser) {
        b.tvUsername.text = dataModel.username
        val status = dataModel.getAccountStatus()
        b.tvStatus.text = when (status) {
            null, AccountStatus.LINK, AccountStatus.PHONE -> ""
            else -> status.cn
        }

        b.tvUsername.setOnClickListener { UserCenterActivity.startActivity(context, dataModel.userId!!) }

        // 图标大小（dp）
        val size = (48 * context.resources.displayMetrics.density).toInt()

        // 加载版面头像
        Glide.with(context)
            .load(dataModel.getAvatars()?.get(0))
            .apply(RequestOptions().circleCrop())
            .error(R.drawable.ic_person_18)
            .transition(DrawableTransitionOptions.withCrossFade(CROSS_FADE))
            .into(TextViewTarget(b.tvUsername, 0, size, size))
    }
}